﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Forms;
using data.contracts;
using ebcbauteile;
using twittersearch;

namespace TwitterBand
{
    public partial class MainWindow : Window
    {
        private string suchbegriff;

        public MainWindow() {
            InitializeComponent();
            EBCs_verdrahten();
        }

        private void EBCs_verdrahten() {
            var twitterSearch = new TwitterSearch();
            var timer = new PeriodicDispenser<string>();
            var synchronizer = new Synchronizer<IEnumerable<Tweet>>();

            Out_Search += timer.In_Event;
            timer.Out_Event += twitterSearch.In_Search;
            twitterSearch.Out_Update += synchronizer.In_Event;
            synchronizer.Out_Event += In_Update;
        }

        private event Action<string> Out_Search;

        private void In_Update(IEnumerable<Tweet> tweets) {
            query.Text = string.Format("Twitter Hashtag {0} benutzen!", suchbegriff);
            update.Text = string.Format("Letzte Aktualisierung: {0:dd.MMM HH:mm}", DateTime.Now);
            lstContent.ItemsSource = tweets;
        }

        public void Fenster_konfigurieren(bool topmost) {
            Left = 0;
            Width = Screen.PrimaryScreen.Bounds.Width;
            Height = 120;
            Top = Screen.PrimaryScreen.Bounds.Height - Height;
            Topmost = topmost;
        }

        public void Suchbegriff_festlegen(string suchbegriff) {
            this.suchbegriff = suchbegriff;
            Out_Search(suchbegriff);
        }
    }
}